﻿#include "CPublicData.h"
#include "PublicGlobal.h"
#include "Global.h"

SINGLETON_STATIC_INITIALIZE(CPublicData)
CPublicData::CPublicData()
{
	//配置文件地址
	QString sFilePath = QCoreApplication::applicationDirPath() + A2T("\\config\\ManualSampleSys.ini");


	//初始化配置
	m_pstMainCfg = new SMainCfg();

	//读取ini配置文件
	readConfigIni(sFilePath);
}

CPublicData::~CPublicData()
{
	SAFE_DELETE(m_pstMainCfg);
}



void CPublicData::readConfigIni(QString sPath)
{
	QFileInfo  file(sPath);
	if (!file.exists())
	{
		QMessageBox::information(NULL, A2T("提示"), A2T("配置文件不存在！"));
		return;
	}
	else
	{
		QSettings setting(sPath, QSettings::IniFormat);
		setting.setIniCodec(QTextCodec::codecForName("UTF-8"));
		QStringList slist = setting.allKeys();
		for (int i = 0; i < slist.size(); i++)
		{
			m_mapCfg.insert(slist.at(i), setting.value(slist.at(i)).toString());
		}
		readConfigIniMain();		//读Main节点
	}
}

void CPublicData::readConfigIniMain()
{
	m_pstMainCfg->nIsAllowRepeateOpen = (int)m_mapCfg.value("MAIN/IsAllowRepeateOpen", "0").toDouble();			//是否允许重复打开		
	m_pstMainCfg->nIsShownLogView = (int)m_mapCfg.value("MAIN/IsShownLogView", "1").toDouble();				    //是否展示日志页
	m_pstMainCfg->nIsLogin = (int)m_mapCfg.value("MAIN/IsLogin", "1").toDouble();								//是否需要登录
	m_pstMainCfg->nIsOpenSyncDb = (int)m_mapCfg.value("MAIN/IsOpenSyncDb", "0").toDouble();						//是否开启数据库同步线程
	g_nProjectNo    = (int)m_mapCfg.value("MAIN/nProjectNo", "1").toDouble();
	g_nPerPageCount = (int)m_mapCfg.value("MAIN/PerPageCount", "10").toDouble();
	g_n6mm1PrintNum  = (int)m_mapCfg.value("MAIN/n6mm1PrintNum", "0").toInt();
	g_n6mm2PrintNum = (int)m_mapCfg.value("MAIN/n6mm2PrintNum", "0").toInt();
	g_n3mmPrintNum  = (int)m_mapCfg.value("MAIN/n3mmPrintNum", "0").toInt();
	g_n2mm3PrintNum  = (int)m_mapCfg.value("MAIN/n2mm3PrintNum", "0").toInt();
	g_n2mm2PrintNum = (int)m_mapCfg.value("MAIN/n2mm2PrintNum", "0").toInt();
	g_nSampleCodePrintNum = (int)m_mapCfg.value("MAIN/nSampleCodePrintNum", "1").toInt();
	g_fStandWeight  = (int)m_mapCfg.value("MAIN/nStandCarNum", "0").toFloat();
	g_nIsOpenPrintExamineCode = (int)m_mapCfg.value("MAIN/nIsOpenPrintExamineCode", "0").toInt();
}

